package com.randy.recyclerviews.helper;

/**
 * Created by xudong on 16/7/22.
 */
public class Range<T extends Comparable<T>> {
    public final T first, second;

    public Range(T first, T second) {
        this.first = first;
        this.second = second;
    }

    public boolean inRange(T value) {
        if (first == null || second == null) return false;

        return first.compareTo(value) <= 0 && second.compareTo(value) > 0;
    }

    public static <T extends Comparable<T>> Range<T> create(T a, T b) {
        return new Range<T>(a, b);
    }

    public static <T extends Comparable<T>> Range<T> empty(T zero) {
        return new Range<T>(zero, zero);
    }

    public boolean isNotEmpty() {
        return first != null && second != null && !first.equals(second);
    }

    public boolean isEmpty() {
        return !isNotEmpty();
    }

    @Override
    public String toString() {
        return String.format("%s:%s", first.toString(), second.toString());
    }
}